package com.company.common.function.interceptor.config;

import com.company.common.function.interceptor.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//拦截器 配置类 拦截器需要配置一些配置策略
@Configuration
public class WebApplicationConfig implements WebMvcConfigurer {

    @Value("${open.url}")
    private String openUrl;

    //指向我们自定义拦截器
    @Bean
    public MyInterceptor myInterceptor() {
        return new MyInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //开放路径与 校验路径
        registry.addInterceptor(myInterceptor()).addPathPatterns("/api/**").excludePathPatterns(openUrl);
    }
}
